package pers.cjr.demo.controller;

import com.corundumstudio.socketio.SocketIOClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import javax.validation.groups.Default;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pers.cjr.common.service.RedisService;
import pers.cjr.common.validator.BizUpdate;
import pers.cjr.demo.model.entity.JpaUser;

@Api(tags = "测试")
@RestController
public class TestController {


    @Autowired
    private RedisService redisService;
    @Resource(name = "h2JdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @ApiOperation("多数据源框架")
    @PostMapping("/db")
    public void db(Model model) throws Exception {
        jdbcTemplate.execute("drop table if exists `jpa_user222`;");
//        jdbcTemplate.execute("CREATE TABLE `jpa_user222` (\n"
//                + "                               `id` bigint NOT NULL AUTO_INCREMENT,\n"
//                + "                               `created_by` varchar(255) DEFAULT NULL,\n"
//                + "                               `created_date` datetime DEFAULT NULL,\n"
//                + "                               `last_updated_by` varchar(255) DEFAULT NULL,\n"
//                + "                               `last_updated_date` datetime DEFAULT NULL,\n"
//                + "                               `name` varchar(255) DEFAULT NULL,\n"
//                + "                               PRIMARY KEY (`id`)\n"
//                + ") ;\n");
    }

    @ApiOperation("参数校验save")
    @PostMapping("/save")
    public void save(@RequestBody @Validated JpaUser user) {
    }

    @ApiOperation("参数校验update")
    @PostMapping("/update")
    public void update(@RequestBody @Validated({BizUpdate.class, Default.class}) JpaUser user) {
    }
}
